import Vue from 'vue'
//1.导入路由插件
import VueRouter from 'vue-router'
//2.将路由插件注册到Vue实例里
Vue.use(VueRouter);

//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push;
//修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
};

const Home = () => import('../views/home/Home.vue')
const Category = () => import('../views/category/Category.vue')
const Cart = () => import('../views/cart/Cart.vue')
const Profile = () => import('../views/profile/Profile.vue')

const routes = [
    {
        path:'/',
        redirect: "/home"
    },
    {
        path:'/home',
        component: Home,
    },
    {
        path:'/category',
        component: Category
    },
    {
        path:'/cart',
        component: Cart
    },
    {
        path:'/profile',
        component: Profile
    }
]

//创建 VueRouter 对象
const router = new VueRouter({
    routes,
    mode: "history", 
  });
  
//3.将router对象传入到 Vue 实例中
export default router;